package cl.scene.libbencode;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: Patricio
 * Date: 23-11-2010
 * Time: 10:06:52 PM
 */
public class ListType implements IContainerType {

    private ArrayList<IType> list;

    public ListType() {
        list = new ArrayList<IType>();
    }

    public ListType(InputStream is, BencodeParser bencodeParser) {
        //To change body of created methods use File | Settings | File Templates.
    }

    public void encodeAndWrite(OutputStream o) throws IOException {
        this.populate();
        o.write('l');
        for(IType v:list) {
            v.encodeAndWrite(o);
        }
        o.write('e');
    }


    public boolean add(IType value) {
        return list.add(value);
    }

    public void populate() {}

    public void push(IType val) {
        add(val);
    }
}
